import java.util.ArrayList;
import java.util.List;

//给你二叉树的根节点 root ，返回它节点值的 前序 遍历。
public class Solution {
    class TreeNode {
        int val = 0;
        TreeNode left = null;
        TreeNode right = null;

        public TreeNode(int val) {
            this.val = val;
        }

        public void preorder(List<Integer> list, TreeNode root){
            if(root == null){
                return;
            }
            list.add(root.val);
            preorder(list,root.left);
            preorder(list,root.right);
        }
        public int[] preorderTraversal (TreeNode root) {
            List<Integer> list = new ArrayList();
            preorder(list,root);
            int[] result = new int[list.size()];
            for(int i = 0; i < list.size(); i++){
                result[i] = list.get(i);
            }
            return result;
        }
    }
}
